/******************************************************************************
 Copyright (c) 2022-2025 Qualcomm Technologies International, Ltd.
 All Rights Reserved.
 Qualcomm Technologies International, Ltd. Confidential and Proprietary.

 REVISION:      $Revision: #4 $
******************************************************************************/

#ifndef GATT_XPAN_SERVER_H
#define GATT_XPAN_SERVER_H

#include "csr_synergy.h"

#ifndef EXCLUDE_GATT_XPAN_SERVER_MODULE

#include "csr_types.h"
#include "library.h"
#include "service_handle.h"
#include "csr_bt_tasks.h"

#define XPAN_SERVER_SERVICE_PRIM     (SYNERGY_EVENT_BASE + XPAN_SERVER_PRIM)

/* Size of an MAC address in octets */
#define GATT_XPAN_SERVER_MAC_ADDRESS_SIZE               (6)
/* Total required octets for the BSSID */
#define GATT_XPAN_SERVER_BSSID_SIZE                     (6)
#define XPAN_WIFI_SCAN_TIMESTAMP_LENGTH                 (8)
#define XPAN_TARGET_TSF_LENGTH                          (8)
#define GATT_XPAN_SERVER_COUNTRY_STRING_SIZE            (3)

/* Ipv4 Address size */
#define GATT_XPAN_SERVER_IPV4_ADDRESS_SIZE                      (4)

/* Ipv6 Address size */
#define GATT_XPAN_SERVER_IPV6_ADDRESS_SIZE                      (16)

/* Temporal key sizes exchanged during wifi handshake */
#define GATT_XPAN_SERVER_WIFI_TEMPORAL_KEY_SIZE                 (16)

/* Octets size of ip addresses lease, renewal or rebinding time */
#define GATT_XPAN_SERVER_IP_ADDRESS_TIME_SIZE                   (4)

/* Octets size of Pairwise Master Key(PMK)*/
#define GATT_XPAN_SERVER_PMK_SIZE                               (32)

/* Octets size of country string*/
#define GATT_XPAN_SERVER_COUNTRY_STRING_SIZE                    (3)

/*
 * The format for the WiFi Scan results is:
 * -----
 * 1 octet : opcode
 * 8 octets: time stamp
 * 1 octets: num BSSIDs
 * ----- For each BSSID
 * 1 octets: SSID len
 * 0 octets: Worst case (is an empty SSID really a valid value)?
 * 6 octets: bssid
 * 2 octets: channel
 * 1 octets: sec mode
 * 1 octets: rssi        = total: 11
 * -----
 */
#define WIFI_SCAN_RESULTS_GLOBAL_FIELDS_SIZE     (1 + /* octet : opcode      */ \
                                                  8 + /* octets: time stamp  */ \
                                                  1   /* octets: num BSSIDs  */ )

#define WIFI_SCAN_RESULTS_SINGLE_AP_RESULT_SIZE    (1 + /* octets: SSID len                                            */ \
                                                    0 + /* octets: Worst case (is an empty SSID really a valid value)? */ \
                                                    6 + /* octets: bssid                                               */ \
                                                    2 + /* octets: channel                                             */ \
                                                    1 + /* octets: sec mode                                            */ \
                                                    1   /* octets: rssi                                                */ )
/*
 * Note: ATT currently limits Long Writes to 250 octets.
 */
#define ATT_MAX_PDU_SIZE                    (250)

#define GATT_XPAN_SERVER_WIFI_SCAN_RESULT_NUM_APS_MAX   ((ATT_MAX_PDU_SIZE - WIFI_SCAN_RESULTS_GLOBAL_FIELDS_SIZE)/WIFI_SCAN_RESULTS_SINGLE_AP_RESULT_SIZE)

#define GATT_XPAN_SERVER_SSID_MAX_LENGTH               (32)
#define GATT_XPAN_SERVER_PASSPHRASE_MIN_LENGTH          (8)
#define GATT_XPAN_SERVER_PASSPHRASE_MAX_LENGTH         (63)

typedef uint8 GattXpanRole;
/*!
    @name XPAN_ROLE
    @brief Values for the roles field.
*/
/*! @{ */
/*! @brief Primary Role value */
#define XPAN_ROLE_PRIMARY                  (0x00u)
/*! @brief Secondary Role value */
#define XPAN_ROLE_SECONDARY                (0x01u)
/*! @} */

typedef uint8 GattXpanIpAddressStatus;
/*!
    @name XPAN_STATUS
    @brief Values for the status field in ipv4 and ipv6 address characteristic.
*/
/*! @{ */
/*! @brief IP Address obtained successfully value */
#define XPAN_STATUS_SUCCESS                                     (0x00u)
/*! @brief Failed to obtain IP Address value */
#define XPAN_STATUS_FAILED                                      (0x01u)
/*! @brief Failed to connect to SSID value - kept for backward compatability*/
#define XPAN_STATUS_TO_CONNECT_SSID                             (0x02u)
/*! @brief Specific error codes when connection to SSID fails */
/*! @brief Network is not reachable value */
#define XPAN_STATUS_NETWORK_NOT_REACHABLE                       (0x02u)
/*! @brief Wi-Fi connection is lost value */
#define XPAN_STATUS_CONNECTION_LOST                             (0x03u)
/*! @brief Wi-Fi connection error value */
#define XPAN_STATUS_WIFI_CONNECTION_ERROR                       (0x04u)
/*! @brief Wi-Fi connection error or password is incorrect value */
#define XPAN_STATUS_WIFI_CONNECTION_ERROR_INCORRECT_PASSWORD    (0x05u)
/*! @brief Wi-Fi connection MIC failure value */
#define XPAN_STATUS_WIFI_CONNECTION_MIC_FAILURE                 (0x06u)
/*! @brief Invalid Wi-Fi Channel value */
#define XPAN_STATUS_INVALID_WIFI_CHANNEL                        (0x07u)
/*! @brief Unknown error value */
#define XPAN_STATUS_UNKNOWN_ERROR                               (0x08u)
/*! @brief Internal error value */
#define XPAN_STATUS_INTERNAL_ERROR                              (0x09u)
/*! @} */

/*!
    @brief Audio Location bitfield. #AUDIO_LOCATION values should be can be combined
           in this type.
*/
typedef uint32 GattXpanAudioLoc;

/*!
    @name AUDIO_LOCATION
    @brief bitfield values for the #GattXpanAudioLoc type. This is stored in big-endian format.
*/
/*! @{ */
/*! @brief Front Left Audio Location bit value */
#define XPAN_AUDIO_LOCATION_FRONT_LEFT                 (0x00000001u)
/*! @brief Front Right Audio Location bit value */
#define XPAN_AUDIO_LOCATION_FRONT_RIGHT                (0x00000002u)
/*! @brief Front Center Audio Location bit value */
#define XPAN_AUDIO_LOCATION_FRONT_CENTER               (0x00000004u)
/*! @brief Low Frequency Effects 1 Audio Location bit value */
#define XPAN_AUDIO_LOCATION_LOW_FREQUENCY_EFFECTS_1    (0x00000008u)
/*! @brief Back Left Audio Location bit value */
#define XPAN_AUDIO_LOCATION_BACK_LEFT                  (0x00000010u)
/*! @brief Back Right Audio Location bit value */
#define XPAN_AUDIO_LOCATION_BACK_RIGHT                 (0x00000020u)
/*! @brief Front Left of Center Audio Location bit value */
#define XPAN_AUDIO_LOCATION_FRONT_LEFT_OF_CENTER       (0x00000040u)
/*! @brief Front Right of Center Audio Location bit value */
#define XPAN_AUDIO_LOCATION_FRONT_RIGHT_OF_CENTER      (0x00000080u)
/*! @brief Back Center Audio Location bit value */
#define XPAN_AUDIO_LOCATION_BACK_CENTER                (0x00000100u)
/*! @brief Low Frequency Effects 2 Audio Location bit value */
#define XPAN_AUDIO_LOCATION_LOW_FREQUENCY_EFFECTS_2    (0x00000200u)
/*! @brief Side Left Audio Location bit value */
#define XPAN_AUDIO_LOCATION_SIDE_LEFT                  (0x00000400u)
/*! @brief Side Right Audio Location bit value */
#define XPAN_AUDIO_LOCATION_SIDE_RIGHT                 (0x00000800u)
/*! @brief Top Front Left Audio Location bit value */
#define XPAN_AUDIO_LOCATION_TOP_FRONT_LEFT             (0x00001000u)
/*! @brief Top Front Right Audio Location bit value */
#define XPAN_AUDIO_LOCATION_TOP_FRONT_RIGHT            (0x00002000u)
/*! @brief Top Front Center Audio Location bit value */
#define XPAN_AUDIO_LOCATION_TOP_FRONT_CENTER           (0x00004000u)
/*! @brief Top Center Audio Location bit value */
#define XPAN_AUDIO_LOCATION_TOP_CENTER                 (0x00008000u)
/*! @brief Top Back Left Audio Location bit value */
#define XPAN_AUDIO_LOCATION_TOP_BACK_LEFT              (0x00010000u)
/*! @brief Top Back Right Audio Location bit value */
#define XPAN_AUDIO_LOCATION_TOP_BACK_RIGHT             (0x00020000u)
/*! @brief Top Side Left Audio Location bit value */
#define XPAN_AUDIO_LOCATION_TOP_SIDE_LEFT              (0x00040000u)
/*! @brief Top Side Right Audio Location bit value */
#define XPAN_AUDIO_LOCATION_TOP_SIDE_RIGHT             (0x00080000u)
/*! @brief Top Back Center Audio Location bit value */
#define XPAN_AUDIO_LOCATION_TOP_BACK_CENTER            (0x00100000u)
/*! @brief Bottom Front Center Audio Location bit value */
#define XPAN_AUDIO_LOCATION_BOTTOM_FRONT_CENTER        (0x00200000u)
/*! @brief Bottom Front Left Audio Location bit value */
#define XPAN_AUDIO_LOCATION_BOTTOM_FRONT_LEFT          (0x00400000u)
/*! @brief Bottom Front Right Audio Location bit value */
#define XPAN_AUDIO_LOCATION_BOTTOM_FRONT_RIGHT         (0x00800000u)
/*! @brief Front Left Wide Audio Location bit value */
#define XPAN_AUDIO_LOCATION_FRONT_LEFT_WIDE            (0x01000000u)
/*! @brief Front Right Wide Audio Location bit value */
#define XPAN_AUDIO_LOCATION_FRONT_RIGHT_WIDE           (0x02000000u)
/*! @brief Left Surround Audio Location bit value */
#define XPAN_AUDIO_LOCATION_LEFT_SURROUND              (0x04000000u)
/*! @brief Right Surround Audio Location bit value */
#define XPAN_AUDIO_LOCATION_RIGHT_SURROUND             (0x08000000u)
/*! @brief Used to set an Invalid Audio Location */
#define XPAN_AUDIO_LOCATION_INVALID                    (0xffffffffu)
/*! @} */

/*!
    @name XPAN_TRANSPORT
    @brief Used to identify the transport for a connected device.
*/
/*! @{ */
/*! @brief Bluetooth TWM transport */
#define XPAN_TRANSPORT_BLUETOOTH_TWM       0x00
/*! @brief Bluetooth LE Audio transport */
#define XPAN_TRANSPORT_BLUETOOTH_LE_AUDIO  0x01
/*! @brief Wi-Fi non 2.4G Point to Point transport */
#define XPAN_TRANSPORT_WI_FI_NON_24G_P2P   0x02
/*! @brief Wi-Fi 2.4G Point to Point transport */
#define XPAN_TRANSPORT_WI_FI_24G_P2P       0x03
/*! @brief Wi-Fi non 2.4G Access Point transport */
#define XPAN_TRANSPORT_WI_FI_NON_24G_AP    0x04
/*! @brief Wi-Fi 2.4G Access Point transport */
#define XPAN_TRANSPORT_WI_FI_24G_AP        0x05
/*! @} */

/*!
    @brief ClearToSend field for the Clear to send characteristic.
*/
typedef uint8 ClearToSend;

/*!
    @name CTS
    @brief values for the #ClearToSend type to indicate whether the client
           is ready to accept audio data over XPAN.
*/
/*! @{ */
/*! @brief Client is ready to accept audio data*/
#define XPAN_CTS_NOT_READY                 0x00
/*! @brief Client is not ready to accept audio data*/
#define XPAN_CTS_READY                     0x01
/*! @} */

typedef uint8 GattXpanSecurityMode;
/*!
    @name SECURITY_MODE
    @brief Values used to set the security mode.
*/
/*! @{ */
/*! @brief Used to set Security Mode to Open */
#define XPAN_SECURITY_MODE_OPEN            0x00
/*! @brief Used to set Security Mode to WEP */
#define XPAN_SECURITY_MODE_WEP             0x01
/*! @brief Used to set Security Mode to WPA */
#define XPAN_SECURITY_MODE_WPA             0x02
/*! @brief Used to set Security Mode to WPA2 */
#define XPAN_SECURITY_MODE_WPA2            0x03
/*! @brief Used to set Security Mode to Mixed Mode */
#define XPAN_SECURITY_MODE_MIXED_MODE      0x04
/*! @brief Used to set Security Mode to WPA3 */
#define XPAN_SECURITY_MODE_WPA3            0x05
/*! @brief Used to set Security Mode WPA Transition */
#define XPAN_SECURITY_MODE_WPA3_TRANSITION 0x06
/*! @brief Used to set Security Mode to Any */
#define XPAN_SECURITY_MODE_ANY             0x07
/*! @brief Used to set Security Mode to Unknown */
#define XPAN_SECURITY_MODE_UNKNOWN         0x08
/*! @brief Used to identify the beginning of the 'reserved' values */
#define XPAN_SECURITY_MODE_MIN_RESERVED_VALUE         0x09
/*! @} */

typedef uint8 GattXpanEnterpriseSecurityMode;
/*!
    @name ENTERPRISE SECURITY_MODE
    @brief Values used to set the enterprise security mode.
*/
/*! @{ */
/*! @brief Used to set Enterprise Security Mode to WPA2 EAP-PEAP LABEL0 MSCHAPv2 */
#define XPAN_ENTERPRISE_SECURITY_MODE_WPA2_EAP_PEAP_LABEL0_MSCHAPv2            0x00
/*! @brief Used to identify the beginning of the 'reserved' values */
#define XPAN_ENTERPRISE_SECURITY_MODE_MIN_RESERVED_VALUE                       0x01
/*! @} */

/*!
    @brief Bearer Preference. #BEARER_PREFERENCE values should be used to
           set this type.
*/
typedef struct
{
    uint8                bearerPreference;
    uint8                urgencyLevel;
} BearerPreference;


/*!
    @name BEARER_PREFERENCE
    @brief Values used to set the Bearer Preference Characteristic for this
           device.
*/
/*! @{ */
/*! @brief Used to set Bearer Preference to None */
#define XPAN_BEARER_PREFERENCE_NONE             0x00
/*! @brief Used to set Bearer Preference to BR/EDR */
#define XPAN_BEARER_PREFERENCE_BREDR            0x01
/*! @brief Used to set Bearer Preference to LE */
#define XPAN_BEARER_PREFERENCE_LE               0x02
/*! @brief Used to set Bearer Preference to XPAN Access Point */
#define XPAN_BEARER_PREFERENCE_XPAN_AP          0x03
/*! @brief Used to set Bearer Preference to XPAN Point to Point */
#define XPAN_BEARER_PREFERENCE_XPAN_P2P         0x04
/*! @brief Used to set Bearer Preference to request a transition from one XPAN AP to another XPAN AP */
#define XPAN_BEARER_PREFERENCE_XPAN_AP_PREP     0x05
/*! @brief Used to set Bearer Preference to XPAN AP Assist */
#define XPAN_BEARER_PREFERENCE_XPAN_AP_ASSIST   0x06
/*! @brief Used to set Bearer Preference to Non XPAN */
#define XPAN_BEARER_PREFERENCE_NON_XPAN         0x07
/*! @brief Used to set Bearer Preference to XPAN Point to Point Prep */
#define XPAN_BEARER_PREFERENCE_XPAN_P2P_PREP    0x08
/*! @brief Max supported Bearer Preference */
#define XPAN_BEARER_PREFERENCE_MAX              XPAN_BEARER_PREFERENCE_XPAN_P2P_PREP

/*! @brief Urgency Levels to set in Bearer Preference */
#define XPAN_URGENCY_LEVEL_NOT_URGENT           0x00
#define XPAN_URGENCY_LEVEL_URGENT               0x01
#define XPAN_URGENCY_LEVEL_MAX                  XPAN_URGENCY_LEVEL_URGENT
/*! @} */

/*!
    @name BEARER_PREFERENCE_STATUS
    @brief The Bearer Preference Status conveys the response from the client (sent in the Bearer Preference Response opcode).
           It is used to inform the server whether the client accepted or rejected the server's bearer preference.
*/
/*! @{ */
/*! @brief Used to set Bearer Preference Status to Accepted */
#define XPAN_SERVER_BEARER_PREFERENCE_STATUS_ACCEPTED  0x00
/*! @brief Used to set Bearer Preference Status to Rejected */
#define XPAN_SERVER_BEARER_PREFERENCE_STATUS_REJECTED  0x01
/*! @} */

/*!
    @name SAP_POWER_STATE
    @brief Values used to set the SAP Power State.
*/
/*! @{ */
/*! @brief Used to set SAP Power State to Deep Sleep */
#define XPAN_SAP_POWER_STATE_DEEP_SLEEP    0x00
/*! @brief Used to set SAP Power State to Active */
#define XPAN_SAP_POWER_STATE_ACTIVE        0x01
/*! @} */

/*!
    @name SAP_POWER_STATE_STATUS
    @brief Values used to set the SAP Power State Response Opcode status.
*/
/*! @{ */
/*! @brief Used to set SAP Power State Status to Accepted */
#define XPAN_SERVER_SAP_POWER_STATE_STATUS_ACCEPTED  0x00
/*! @brief Used to set SAP Power State Status to Rejected */
#define XPAN_SERVER_SAP_POWER_STATE_STATUS_REJECTED  0x01
/*! @} */

/*!
    @brief Server status. #GATT_XPAN_SERVER_FEATURES values should be used to
           set this type.
*/
typedef uint8 XpanServerFeatures[8];
/*!
    @name GATT_XPAN_SERVER_FEATURES
    @brief Values used for setting the bits in the XPAN ServerFeatures characteristics.
           This is stored in little-endian format
*/
/*! @{ */
/*! @brief Used to set the server feature bit for XPAN 2.4 GHz bearer. */       
#define XPAN_SERVER_FEATURE_XPAN_24G_BEARER                                     (0x80000000u)
/*! @brief Used to set the server feature bit for XPAN 5 GHz bearer.*/          
#define XPAN_SERVER_FEATURE_5G_BEARER                                           (0x40000000u)
/*! @brief Used to set the server feature bit for XPAN 6 GHz bearer. */         
#define XPAN_SERVER_FEATURE_6G_BEARER                                           (0x20000000u)
/*! @brief Used to set the server feature bit for XPAN point to point topology. */
#define XPAN_SERVER_FEATURE_P2P_TOPOLOGY                                        (0x10000000u)
/*! @brief Used to set the server feature bit for XPAN access point topology. */
#define XPAN_SERVER_FEATURE_AP_TOPOLOGY                                         (0x08000000u)
/*! @brief Used to set the server feature bit for XPAN P2P audio bearer. */     
#define XPAN_SERVER_FEATURE_P2P_AUDIO_BEARER                                    (0x04000000u)
/*! @brief Used to set the server feature bit for XPAN AP audio bearer. */      
#define XPAN_SERVER_FEATURE_AP_AUDIO_BEARER                                     (0x02000000u)
/*! @brief Used to set the server feature bit for Bearer switch between Bluetooth and 2.4 GHz AP. */
#define XPAN_SERVER_FEATURE_BEARER_SWITCH_BT_24G_AP                             (0x01000000u)
/*! @brief Used to set the server feature bit for Bearer switch between Bluetooth and 5 GHz (or higher) AP. */
#define XPAN_SERVER_FEATURE_BEARER_SWITCH_BT_5G_AP                              (0x00800000u)
/*! @brief Used to set the server feature bit for Audio bearer switch between Bluetooth and SAP. */
#define XPAN_SERVER_FEATURE_AUDIO_BEARER_SWITCH_BT_SAP                          (0x00400000u)
/*! @brief Used to set the server feature bit for Bearer switch between 2.4 GHz AP and 5 GHz (or higher) AP. */
#define XPAN_SERVER_FEATURE_BEARER_SWITCH_24G_AP_5G_AP                          (0x00200000u)
/*! @brief Used to set the server feature bit for Full bearer switch during an LE audio stream. */
#define XPAN_SERVER_FEATURE_FULL_BEARER_SWITCH_LE_AUDIO_STREAM                  (0x00100000u)
/*! @brief Used to set the server feature bit for Switch primary procedure. */ 
#define XPAN_SERVER_FEATURE_SWITCH_PRIMARY_PROCEDURE                            (0x00080000u)
/*! @brief Used to set the server feature bit for TLS 1.2 */                   
#define XPAN_SERVER_FEATURE_TLS_12                                              (0x00040000u)
/*! @brief Used to set the server feature bit for DTLS. */                     
#define XPAN_SERVER_FEATURE_DTLS                                                (0x00020000u)
/*! @brief Used to set the server feature bit for  Voice call over XPAN P2P bearer. */
#define XPAN_SERVER_FEATURE_VOICE_CALL_XPAN_P2P_BEARER                          (0x00010000u)
/*! @brief Used to set the server feature bit for mDNS. */                      
#define XPAN_SERVER_FEATURE_MDNS                                                (0x00008000u)
/*! @brief Used to set the server feature bit for Gaming Audio over AP. */      
#define XPAN_SERVER_FEATURE_GAMING_AUDIO_OVER_AP                                (0x00004000u)
/*! @brief Used to set the server feature bit for TLS 1.3 */                    
#define XPAN_SERVER_FEATURE_TLS_13                                              (0x00002000u)
/*! @brief Used to set the server feature bit for Enterprise Support. */        
#define XPAN_SERVER_FEATURE_ENTERPRISE_SUPPORT                                  (0x00001000u)
/*! @brief Used to set the server feature bit for Enterprise certificate-based Wi-Fi Authentication. */
#define XPAN_SERVER_FEATURE_ENTERPRISE_CERTIFICATE_BASED_WIFI_AUTHENTICATION	(0x00000800u)
/*! @} */

/*!
    @brief Type used for the Audio bearer switch response characteristic. Value can be set using #AUDIO_BEARER_SWITCH_RESPONSE values
*/
typedef uint8 XpanAudioBearerSwitchResponse;

/*!
    @name AUDIO_BEARER_SWITCH_RESPONSE
    @brief values for the #XpanAudioBearerSwitchResponse type to indicate whether the client
           is ready to accept audio data over XPAN.
*/
/*! @{ */
/*! @brief Client is ready to perform audio bearer switch. */
#define XPAN_AUDIO_BEARER_SWITCH_RESPONSE_READY                 0x00
/*! @brief Client is failed to perform audio bearer switch. */
#define XPAN_AUDIO_BEARER_SWITCH_RESPONSE_FAILED                0x01
/*! @} */

/*!
    @brief Type used for the Audio bearer switch request opcode. Value can be set using #AUDIO_BEARER_SWITCH_REQUEST values
*/
typedef uint8 XpanAudioBearerSwitchRequest;

/*!
    @name AUDIO_BEARER_SWITCH_REQUEST
    @brief values for the #XpanAudioBearerSwitchRequest type to indicate the bearer the
           client would like the server stream audio over.
*/
/*! @{ */
/*! @brief Client is requesting the server switch audio streaming bearer to Bluetooth. */
#define XPAN_AUDIO_BEARER_SWITCH_REQUEST_BT                     0x00
/*! @brief Client is requesting the server switch audio streaming bearer to XPAN P2P. */
#define XPAN_AUDIO_BEARER_SWITCH_REQUEST_XPAN_P2P               0x01
/*! @} */

/*!
    @brief Server status. #GATT_XPAN_ROAMING_REQUEST_STATUS_CODES values should be used to
           set this type.
*/
typedef uint8 XpanRoamingRequestStatus;

/*!
    @name GATT_XPAN_ROAMING_REQUEST_STATUS_CODES
    @brief Values used for Status for Roaming Request Response characteristic codes.
*/
/*! @{ */
/*! @brief Used to return a Request Accepted status */
#define GATT_XPAN_ROAMING_REQUEST_ACCEPTED                      0x00
/*! @brief Used to return a Request Accepted status */
#define GATT_XPAN_ROAMING_REQUEST_REJECTED                      0x01
/*! @} */

/*!
    @brief Server status. #GATT_XPAN_ERROR_CODES values should be used to
           set this type.
*/
typedef uint16 GattXpanServerStatus;

/*!
    @name GATT_XPAN_ERROR_CODES
    @brief Values used for error codes.
*/
/*! @{ */
/*! @brief Used to return a Generic error */
#define GATT_XPAN_GENERIC_ERROR                            0x80
/*! @brief Used to return an Invalid Length error */
#define GATT_XPAN_INVALID_LENGTH                           0x81
/*! @brief Used to return an Invalid Data error */
#define GATT_XPAN_INVALID_DATA                             0x82
/*! @brief Used to return unsupported opcode error */
#define GATT_XPAN_SERVER_ERR_UNSUPPORTED_OPCODE            0x9F
/*! @} */

#define GATT_XPAN_SERVER_STATUS_SUCCESS                    (0x0000u)  /*!> Request was a success */
#define GATT_XPAN_SERVER_STATUS_REGISTRATION_FAILED        (0x0001u)  /*!> Request was a failure */

/*! @brief Enumeration of messages an application task can receive from the
*          GATT XPAN Server Library as a result of change in characteristic.
*          Messages need to be freed in the application.
*/
#define GATT_XPAN_SERVER_TWT_CONFIGURATION_IND             GATT_XPAN_SERVER_MESSAGE_BASE

/*! @brief Enumeration of messages an application task can receive from the
*          GATT XPAN Server Library as a result of receiving an opcode from the client.
*          These indications must be freed in the application.
*/
typedef uint16 GattXpanMessageId;
typedef uint8  RequestedSapPowerState;

#define GATT_XPAN_SERVER_CONNECT_SSID_IND                  (GATT_XPAN_SERVER_MESSAGE_BASE + 0x0001u)
#define GATT_XPAN_SERVER_DISCONNECT_SSID_IND               (GATT_XPAN_SERVER_MESSAGE_BASE + 0x0002u)
#define GATT_XPAN_SERVER_CONNECTED_SSID_IND                (GATT_XPAN_SERVER_MESSAGE_BASE + 0x0003u)
#define GATT_XPAN_SERVER_AVAILABLE_SSID_IND                (GATT_XPAN_SERVER_MESSAGE_BASE + 0x0004u)
#define GATT_XPAN_SERVER_RELATED_SSID_IND                  (GATT_XPAN_SERVER_MESSAGE_BASE + 0x0005u)
#define GATT_XPAN_SERVER_MDNS_SRV_UUID_IND                 (GATT_XPAN_SERVER_MESSAGE_BASE + 0x0006u)
#define GATT_XPAN_SERVER_REMOVE_SSID_IND                   (GATT_XPAN_SERVER_MESSAGE_BASE + 0x0007u)
#define GATT_XPAN_SERVER_L2CAP_TCP_PORT_IND                (GATT_XPAN_SERVER_MESSAGE_BASE + 0x0008u)
#define GATT_XPAN_SERVER_UDP_PORT_IND                      (GATT_XPAN_SERVER_MESSAGE_BASE + 0x0009u)
#define GATT_XPAN_SERVER_ETHER_TYPE_IND                    (GATT_XPAN_SERVER_MESSAGE_BASE + 0x000Au)
#define GATT_XPAN_SERVER_MAC_ADDRESS_IND                   (GATT_XPAN_SERVER_MESSAGE_BASE + 0x000Bu)
#define GATT_XPAN_SERVER_BEARER_PREFERENCE_RESPONSE_IND    (GATT_XPAN_SERVER_MESSAGE_BASE + 0x000Cu)
#define GATT_XPAN_SERVER_UPDATE_BEACON_PARAMETERS_IND      (GATT_XPAN_SERVER_MESSAGE_BASE + 0x000Du)
#define GATT_XPAN_SERVER_SAP_POWER_STATE_RESPONSE_IND      (GATT_XPAN_SERVER_MESSAGE_BASE + 0x000Eu)
#define GATT_XPAN_SERVER_CLIENT_FEATURES_IND               (GATT_XPAN_SERVER_MESSAGE_BASE + 0x000Fu)
#define GATT_XPAN_SERVER_AUDIO_BEARER_SWITCH_REQUEST_IND   (GATT_XPAN_SERVER_MESSAGE_BASE + 0x0010u)
#define GATT_XPAN_SERVER_WIFI_SCAN_RESULTS_IND             (GATT_XPAN_SERVER_MESSAGE_BASE + 0x0011u)
#define GATT_XPAN_SERVER_CHANNEL_SWITCH_ANNOUNCEMENT_IND   (GATT_XPAN_SERVER_MESSAGE_BASE + 0x0012u)
#define GATT_XPAN_SERVER_UDP_SYNC_PORT_IND                 (GATT_XPAN_SERVER_MESSAGE_BASE + 0x0013u)
#define GATT_XPAN_SERVER_ROAMING_REQUEST_IND               (GATT_XPAN_SERVER_MESSAGE_BASE + 0x0014u)
#define GATT_XPAN_SERVER_MULTICAST_MAC_ADDRESS_IND         (GATT_XPAN_SERVER_MESSAGE_BASE + 0x0015u)
#define GATT_XPAN_SERVER_USECASE_IDENTIFIER_IND            (GATT_XPAN_SERVER_MESSAGE_BASE + 0x0016u)
#define GATT_XPAN_SERVER_AP_CONNECT_ASSIST_IND             (GATT_XPAN_SERVER_MESSAGE_BASE + 0x0017u)
#define GATT_XPAN_SERVER_WIFI_CHANNEL_SWITCH_RESPONSE_IND  (GATT_XPAN_SERVER_MESSAGE_BASE + 0x0018u)
#define GATT_XPAN_SERVER_BEARER_SWITCH_FAILED_IND          (GATT_XPAN_SERVER_MESSAGE_BASE + 0x0019u)
#define GATT_XPAN_SERVER_COUNTRY_STRING_IND                (GATT_XPAN_SERVER_MESSAGE_BASE + 0x001Au)
#define GATT_XPAN_SERVER_SAP_STATE_IND                     (GATT_XPAN_SERVER_MESSAGE_BASE + 0x001Bu)
#define GATT_XPAN_SERVER_CONNECTED_ENTERPRISE_SSID_IND     (GATT_XPAN_SERVER_MESSAGE_BASE + 0x001Cu)

#define GATT_XPAN_SERVER_CHARAC_BASE                       (GATT_XPAN_SERVER_MESSAGE_BASE + 0x0040u)

#define GATT_XPAN_SERVER_STORED_SSIDS_READ_IND                      (GATT_XPAN_SERVER_CHARAC_BASE + 0x0001u)
#define GATT_XPAN_SERVER_IPV4_ADDRESSES_READ_IND                    (GATT_XPAN_SERVER_CHARAC_BASE + 0x0002u)
#define GATT_XPAN_SERVER_IPV6_ADDRESSES_READ_IND                    (GATT_XPAN_SERVER_CHARAC_BASE + 0x0003u)
#define GATT_XPAN_SERVER_L2CAP_TCP_PORT_READ_IND                    (GATT_XPAN_SERVER_CHARAC_BASE + 0x0004u)
#define GATT_XPAN_SERVER_UDP_PORT_READ_IND                          (GATT_XPAN_SERVER_CHARAC_BASE + 0x0005u)
#define GATT_XPAN_SERVER_MDNS_UUID_READ_IND                         (GATT_XPAN_SERVER_CHARAC_BASE + 0x0006u)
#define GATT_XPAN_SERVER_TWT_CONFIGURATION_READ_IND                 (GATT_XPAN_SERVER_CHARAC_BASE + 0x0007u)
#define GATT_XPAN_SERVER_CONNECTED_DEVICES_READ_IND                 (GATT_XPAN_SERVER_CHARAC_BASE + 0x0008u)
#define GATT_XPAN_SERVER_CLEAR_TO_SEND_READ_IND                     (GATT_XPAN_SERVER_CHARAC_BASE + 0x0009u)
#define GATT_XPAN_SERVER_XPAN_RESERVED_01_READ_IND                  (GATT_XPAN_SERVER_CHARAC_BASE + 0x000Au)
#define GATT_XPAN_SERVER_BEARER_PREFERENCE_READ_IND                 (GATT_XPAN_SERVER_CHARAC_BASE + 0x000Bu)
#define GATT_XPAN_SERVER_MAC_ADDRESSES_READ_IND                     (GATT_XPAN_SERVER_CHARAC_BASE + 0x000Cu)
#define GATT_XPAN_SERVER_REQUESTED_SAP_POWER_STATE_READ_IND         (GATT_XPAN_SERVER_CHARAC_BASE + 0x000Du)
#define GATT_XPAN_SERVER_SERVER_FEATURES_READ_IND                   (GATT_XPAN_SERVER_CHARAC_BASE + 0x000Eu)
#define GATT_XPAN_SERVER_AUDIO_BEARER_SWITCH_RESPONSE_READ_IND      (GATT_XPAN_SERVER_CHARAC_BASE + 0x000Fu)
#define GATT_XPAN_SERVER_NUM_DEVICES_PRESENT_READ_IND               (GATT_XPAN_SERVER_CHARAC_BASE + 0x0010u)
#define GATT_XPAN_SERVER_VOICE_BACK_CHANNEL_PERIODICITY_READ_IND    (GATT_XPAN_SERVER_CHARAC_BASE + 0x0011u)
#define GATT_XPAN_SERVER_XPAN_RESERVED_02_READ_IND                  (GATT_XPAN_SERVER_CHARAC_BASE + 0x0012u)
#define GATT_XPAN_SERVER_XPAN_RESERVED_03_READ_IND                  (GATT_XPAN_SERVER_CHARAC_BASE + 0x0013u)
#define GATT_XPAN_SERVER_XPAN_RESERVED_04_READ_IND                  (GATT_XPAN_SERVER_CHARAC_BASE + 0x0014u)
#define GATT_XPAN_SERVER_XPAN_RESERVED_05_READ_IND                  (GATT_XPAN_SERVER_CHARAC_BASE + 0x0015u)
#define GATT_XPAN_SERVER_XPAN_RESERVED_06_READ_IND                  (GATT_XPAN_SERVER_CHARAC_BASE + 0x0016u)
#define GATT_XPAN_SERVER_XPAN_RESERVED_07_READ_IND                  (GATT_XPAN_SERVER_CHARAC_BASE + 0x0017u)
#define GATT_XPAN_SERVER_TWT_STATUS_READ_IND                        (GATT_XPAN_SERVER_CHARAC_BASE + 0x0018u)
#define GATT_XPAN_SERVER_SAP_CONNECTION_STATUS_READ_IND             (GATT_XPAN_SERVER_CHARAC_BASE + 0x0019u)

#define GATT_XPAN_SERVER_INTERNAL_MESSAGE_BASE                      (GATT_XPAN_SERVER_CHARAC_BASE + 0x0040u)

#define GATT_XPAN_SERVER_CLIENT_CONFIG_CHANGED_IND                  (GATT_XPAN_SERVER_INTERNAL_MESSAGE_BASE + 0x0001u)

/*!
    @name GATT_XPAN_CHARACTERISTICS_MASK_SIZE
    @brief Values used for Characteristic BitMask size.
*/
#define GATT_XPAN_CHARACTERISTICS_MASK_SIZE                                 (1)

#define GATT_XPAN_CHARACTERISTICS_MASK_STORED_SSIDS                         ((0x1) << 0)
#define GATT_XPAN_CHARACTERISTICS_MASK_IPV4_ADDRESSES                       ((0x1) << 1)
#define GATT_XPAN_CHARACTERISTICS_MASK_IPV6_ADDRESSES                       ((0x1) << 2)
#define GATT_XPAN_CHARACTERISTICS_MASK_L2CAP_TCP_PORT                       ((0x1) << 3)
#define GATT_XPAN_CHARACTERISTICS_MASK_UDP_PORT                             ((0x1) << 4)
#define GATT_XPAN_CHARACTERISTICS_MASK_MDNS_UUID                            ((0x1) << 5)
#define GATT_XPAN_CHARACTERISTICS_MASK_TWT_CONFIGURATION                    ((0x1) << 6)
#define GATT_XPAN_CHARACTERISTICS_MASK_CONNECTED_DEVICES                    ((0x1) << 7)
#define GATT_XPAN_CHARACTERISTICS_MASK_CLEAR_TO_SEND                        ((0x1) << 8)
#define GATT_XPAN_CHARACTERISTICS_MASK_RESERVED_01                          ((0x0) << 9)
#define GATT_XPAN_CHARACTERISTICS_MASK_BEARER_PREFERENCE                    ((0x1) << 10)
#define GATT_XPAN_CHARACTERISTICS_MASK_MAC_ADDRESSES                        ((0x1) << 11)
#define GATT_XPAN_CHARACTERISTICS_MASK_REQUESTED_SAP_POWER_STATE            ((0x1) << 12)
#define GATT_XPAN_CHARACTERISTICS_MASK_SERVER_FEATURES                      ((0x1) << 13)
#define GATT_XPAN_CHARACTERISTICS_MASK_AUDIO_BEARER_SWITCH_RESPONSE         ((0x1) << 14)
#define GATT_XPAN_CHARACTERISTICS_MASK_NUM_DEVICES_PRESENT                  ((0x1) << 15)
#define GATT_XPAN_CHARACTERISTICS_MASK_VOICE_BACK_CHANNEL_PERIODICITY       ((0x1) << 16)
#define GATT_XPAN_CHARACTERISTICS_MASK_RESERVED_02                          ((0x0) << 17)
#define GATT_XPAN_CHARACTERISTICS_MASK_RESERVED_03                          ((0x0) << 18)
#define GATT_XPAN_CHARACTERISTICS_MASK_RESERVED_04                          ((0x0) << 19)
#define GATT_XPAN_CHARACTERISTICS_MASK_RESERVED_05                          ((0x0) << 20)
#define GATT_XPAN_CHARACTERISTICS_MASK_RESERVED_06                          ((0x0) << 21)
#define GATT_XPAN_CHARACTERISTICS_MASK_RESERVED_07                          ((0x0) << 22)
#define GATT_XPAN_CHARACTERISTICS_MASK_TWT_STATUS                           ((0x1) << 23)
#define GATT_XPAN_CHARACTERISTICS_MASK_SAP_CONNECTION_STATUS                ((0x1) << 24)

typedef uint8           ServiceUuid;
typedef uint8           PresentDevices;
typedef uint8           VoiceBackChannelPeriodicity;
typedef uint32          TwtStatus;
typedef uint32          SapConnectionStatus;

/*! @brief SsidData (Service Set ID) tuple struct.
*/
typedef struct
{
    uint8 ssidLength;
    uint8 *ssid;
} SsidData;

/*! @brief The passphrase is a variable length field between that shall be equal to 0
 *         if Security Mode is 0x00 (Open). Otherwise it shall be >= 8 octets and <= 63 octets.
*/
typedef struct
{
    uint8 length;
    uint8 *value;
} Passphrase;

/*! @brief The password and identity is a variable length field between that shall be 
 *   >= 0 octets and <= 255 octets.
*/

typedef Passphrase Password, Identity;
/*! @brief ipv4AddressData tuple struct.
*/
typedef struct
{
    uint8               ipv4Address[4];
    uint8               macAddress[GATT_XPAN_SERVER_MAC_ADDRESS_SIZE];
    GattXpanAudioLoc    audioLocation;
    uint8               role;
    uint8               status;
} Ipv4AddressData;

/*! @brief ipv4Ssid tuple struct.
*/
typedef struct
{
    SsidData        ipv4Ssid;
    uint8           bssid[GATT_XPAN_SERVER_BSSID_SIZE];
    uint8           numIpv4Addresses;
    Ipv4AddressData *ipv4Addresses;
} Ipv4Ssid;

/*! @brief IPv4 address characteristic struct.
*/
typedef struct
{
    uint8    numSsids;
    Ipv4Ssid *ipv4Ssids;
} Ipv4Address;

/*! @brief ipv6AddressData tuple struct.
*/
typedef struct
{
    uint8               ipv6Address[16];
    uint8               macAddress[GATT_XPAN_SERVER_MAC_ADDRESS_SIZE];
    GattXpanAudioLoc    audioLocation;
    uint8               role;
    uint8               status;
} Ipv6AddressData;

/*! @brief ipv6Ssid tuple struct.
*/
typedef struct
{
    SsidData        ipv6Ssid;
    uint8           bssid[GATT_XPAN_SERVER_BSSID_SIZE];
    uint8           numIpv6Addresses;
    Ipv6AddressData *ipv6Addresses;
} Ipv6Ssid;

/*! @brief IPv6 Address characteristic struct.
*/
typedef struct
{
    uint8    numSsids;
    Ipv6Ssid *ipv6Ssids;
} Ipv6Address;

/*! @brief Stored ssid (Service Set ID) characteristic struct.
*/
typedef struct
{
    SsidData *ssid;
    uint8    numSsid;
} StoredSsid;


/*! @brief MacAddressData tuple struct.
*/
typedef struct
{
    GattXpanAudioLoc audioLocation;
    uint8            macAddress[GATT_XPAN_SERVER_MAC_ADDRESS_SIZE];
} MacAddressData;

/*! @brief Mac address characteristic struct.
*/
typedef struct
{
    MacAddressData *macAddressData;
    uint8          numMacAddresses;
} MacAddress;

/*! @brief Definition of data for TWT configuration characteristic.
*/
typedef struct
{
    uint8  setupId;
    uint32 desiredWakeDuration; /*!< range: 0 to 0xFFFFFFFF (8 'F's) in microseconds */
    uint32 desiredWakeInterval; /*!< range: 0 to 0xFFFFFFFF (8 'F's) in microseconds */
    uint32 desiredWakeTsfLeft[2]; /*!< range: 0 to 0xFFFFFFFFFFFFFFFF (16 'F's) in microseconds, 0 indicates field invalid, this is stored in little-endian. */
    uint32 desiredWakeTsfRightOffset; /*!< range: 0 to 0xFFFFFFFF (8 'F's) in microseconds */
    uint8  bitfield;
} TwtConfiguration;

/*! @brief Bssid tuple.
*/
typedef struct
{
    uint8 bssid[GATT_XPAN_SERVER_BSSID_SIZE];
    uint16 primaryFrequency;
} Bssid;

/*! @brief Contents of the GATT_XPAN_SERVER_CONNECT_SSID_IND message that is sent by the library
           when the server receives a Connect Ssid opcode from the client.
*/
typedef struct
{
    GattXpanMessageId    id;
    ConnectionId         cid;
    SsidData             connectSsid;
    uint8                passphraseLength;
    uint8                *passPhrase;
    uint8                bssid[GATT_XPAN_SERVER_BSSID_SIZE];
    uint16               primaryFrequency;
    GattXpanSecurityMode securityMode;
    uint8                countryString[GATT_XPAN_SERVER_COUNTRY_STRING_SIZE];
    uint8                *pmk;
} GattXpanConnectSsidInd;

/*! @brief Contents of the GATT_XPAN_SERVER_DISCONNECT_SSID_IND message that is sent by the library
           when the server receives a Disconnect Ssid opcode from the client.
 */
typedef struct
{
    GattXpanMessageId id;
    ConnectionId      cid;
    SsidData          disconnectSsid;
} GattXpanDisconnectSsidInd;

/*! @brief Contents of the GATT_XPAN_SERVER_CONNECTED_SSID_IND message that is sent by the library
           when the server receives a Connected Ssid opcode from the client.
 */
typedef struct
{
    GattXpanMessageId id;
    ConnectionId      cid;
    SsidData          connectedSsid;
    uint8             bssid[GATT_XPAN_SERVER_BSSID_SIZE];
    uint16            primaryFrequency;
    uint8             ipv4Address[4];
    uint8             ipv6Address[16];
    uint8             macAddress[GATT_XPAN_SERVER_MAC_ADDRESS_SIZE];
    Passphrase        passphrase;
    uint8             securityMode;
    uint8             countryString[GATT_XPAN_SERVER_COUNTRY_STRING_SIZE];
    uint8             *pmk;
} GattXpanConnectedSsidInd;

/*! @brief Contents of the GATT_XPAN_SERVER_AVAILABLE_SSID_IND message that is sent by the library
           when the server receives an Available Ssid opcode from the client.
 */
typedef struct
{
    GattXpanMessageId    id;
    ConnectionId         cid;
    SsidData             availableSsid;
    uint8                passphraseLength;
    uint8                *passphrase;
    GattXpanSecurityMode securityMode;
    uint8                numBssid;
    Bssid                *bssidData;
    uint8                *pmk;
} GattXpanAvailableSsidInd;

/*! @brief Contents of the GATT_XPAN_SERVER_RELATED_SSID_IND message that is sent by the library,
           when the server receives a Related Ssid opcode from the client.
 */
typedef struct
{
    GattXpanMessageId id;
    ConnectionId      cid;
    uint8             numSsids;
    SsidData          *relatedSsid;
} GattXpanRelatedSsidInd;

/*! @brief Contents of the GATT_XPAN_SERVER_MDNS_SRV_UUID_IND message that is sent by the library
           when the server receives a mDns Srv Uuid opcode from the client.
 */
typedef struct
{
    GattXpanMessageId id;
    ConnectionId      cid;
    uint8             mDnsSrvUuid[16];
} GattXpanMdnsSrvUuidInd;

/*! @brief Contents of the GATT_XPAN_SERVER_REMOVE_SSID_IND message that is sent by the library
           when the server receives a Remove Ssid opcode from the client.
 */
typedef struct
{
    GattXpanMessageId id;
    ConnectionId      cid;
    SsidData          removeSsid;
} GattXpanRemoveSsidInd;

/*! @brief Contents of the GATT_XPAN_SERVER_L2CAP_TCP_PORT_IND message that is sent by the library
           when the server receives a L2cap Tcp Port opcode from the client.
 */
typedef struct
{
    GattXpanMessageId id;
    ConnectionId      cid;
    /*! The l2capTcpPort value stores the TCP port number on the client, that the server uses
     *  to establish a TCP/IP connection to carry the L2CAP traffic.
     *  This l2capTcpPort number shall be connectable on the client, using the IP addresses exposed
     *  by the client.     */
    uint16            l2capTcpPort;
} GattXpanL2capTcpPortInd;

/*! @brief Contents of the GATT_XPAN_SERVER_UDP_PORT_IND message that is sent by the library
           when the server receives a udp port opcode from the client.
 */
typedef struct
{
    GattXpanMessageId id;
    ConnectionId      cid;
    /*! The udpPortAudio value stores the port number on the client, that the server can send audio
     *  packets to.
     *  This port number shall be available using the IP addresses exposed by the client.*/
    uint16            udpPortAudio;
    uint16            udpPortReports;
} GattXpanUdpPortInd;

/*! @brief Contents of the GATT_XPAN_SERVER_ETHER_TYPE_IND message that is sent by the library
           when the server receives an ether type opcode from the client.
 */
typedef struct
{
    GattXpanMessageId id;
    ConnectionId      cid;
    uint16            etherType;
} GattXpanEtherTypeInd;

/*! @brief Contents of the GATT_XPAN_SERVER_MAC_ADDRESS_IND message that is sent by the library
           when the server receives a mac address opcode from the client.
 */
typedef struct
{
    GattXpanMessageId id;
    ConnectionId      cid;
    uint8             macAddress[GATT_XPAN_SERVER_MAC_ADDRESS_SIZE];
} GattXpanMacAddressInd;

/*! @brief Contents of the GATT_XPAN_SERVER_BEARER_PREFERENCE_IND message that is sent by the library
           when the server receives a bearer preference opcode from the client.
 */
typedef struct
{
    GattXpanMessageId id;
    ConnectionId      cid;
    uint8             status;
} GattXpanBearerPreferenceResponseInd;

/*! @brief Contents of the GATT_XPAN_SERVER_UPDATED_BEACON_PARAMETERS_IND message that is sent by the library
           when the server receives an Updated Beacon Parameters opcode from the client.
 */
typedef struct
{
    GattXpanMessageId id;
    ConnectionId      cid;
    uint8             nextTbttTsf[8];
    uint16            beaconIntervalMultiplier;
    uint16            primaryFrequency;
} GattXpanUpdateBeaconParametersInd;

/*! @brief Contents of the GATT_XPAN_SERVER_SAP_POWER_STATE_RESPONSE_IND message that is sent by the library
           when the server receives a SAP power state response opcode from the client.
 */
typedef struct
{
    GattXpanMessageId          id;
    ConnectionId               cid;
    RequestedSapPowerState     status;
} GattXpanSapPowerStateResponseInd;

/*! @brief Contents of the GATT_XPAN_SERVER_TWT_CONFIGURATION_IND message that is sent by the library
           when the client changes the Twt Configuration characteristic.
 */
typedef struct __GattXpanServerTwtConfigurationInd
{
    GattXpanMessageId id;
    ServiceHandle     xpanServiceHandle;
    ConnectionId      cid;
    TwtConfiguration  twtConfig;
} GattXpanServerTwtConfigurationInd;

/*! @brief Contents of the GATT_XPAN_SERVER_CLIENT_FEATURES_IND message that is sent by the library
           when the server receives a Client Features opcode from the client.
 */
typedef struct
{
    GattXpanMessageId     id;
    ConnectionId          cid;
    XpanServerFeatures    features;
} GattXpanClientFeaturesInd;

/*! @brief Contents of the GATT_XPAN_SERVER_AUDIO_BEARER_SWITCH_REQUEST_IND message that is sent by the library
           when the server receives an Audio Bearer Switch Request opcode from the client.
 */
typedef struct
{
    GattXpanMessageId                id;
    ConnectionId                     cid;
    XpanAudioBearerSwitchRequest     audioBearer;
} GattXpanAudioBearerSwitchRequestInd;

/*! @brief Contents of the GATT_XPAN_SERVER_BEARER_PREFERENCE_READ_IND message that is sent by the library
           when the server receives a Bearer Preference Read Request from the Application.
 */
typedef struct
{
    GattXpanMessageId id;
    ConnectionId      cid;
} GattXpanBearerPreferenceReadInd;

/*! @brief Contents of the GATT_XPAN_SERVER_CLIENT_CONFIG_CHANGED_IND message that is sent by the library
           when the server receives a write access on Client Config from the client.
 */
typedef struct
{
    GattXpanMessageId id;
    ConnectionId      cid;
} GattXpanClientConfigChangedInd;

/*! @brief Definition of data for connected devices characteristic.
*/
typedef struct
{
    uint8  transport;     /*!< Valid values can be found above >*/
    uint16 primaryFrequency;
} ConnectedDevicesData;

typedef struct
{
    uint8                numDevices;
    ConnectedDevicesData *connectedDevice;
} ConnectedDevices;

typedef struct
{
    /*
     * NOTE: This is NOT the order that fields are received over the air, but this ordering does
     * make the struct smaller
     */
    uint8                bssid[GATT_XPAN_SERVER_BSSID_SIZE];
    uint8                ssidLength;
    uint8*               ssid;  /*! The App must free the memory pointed to here */
    uint16               channelMHz;
    GattXpanSecurityMode securityMode;
    int8                 rssi;
} ApScanResult;

typedef struct
{
    SsidData             connectSsid;
    uint8                bssid[GATT_XPAN_SERVER_BSSID_SIZE];
    uint16               channel;
    GattXpanSecurityMode securityMode;
    uint8                rssiOfAp;
}WiFiScanResultsBssIdData;

typedef struct
{
    uint8                     timestamp[XPAN_WIFI_SCAN_TIMESTAMP_LENGTH];
    uint8                     numBssId;
    WiFiScanResultsBssIdData* bssIdData;
}WiFiScanResults;

typedef struct
{
    uint8                numChannels;
    uint16*              centerFrequency;
}PreferredChannels;

typedef PreferredChannels SupportedWiFiChannels;

typedef uint16 XpanWiFiChannelSwitchRequestPriFreq;

/*! @brief Contents of the GATT_XPAN_SERVER_WIFI_SCAN_RESULTS_IND message that is sent by the XPAN Service library
           when it receives a WiFi Scan Results opcode from the Handset.
           In theory the number of ApScanResults can be GATT_XPAN_SERVER_WIFI_SCAN_RESULT_NUM_APS_MAX, so we need
           to cater for this, just in case someone is trying to break things.
 */
typedef struct
{
    GattXpanMessageId id;
    ConnectionId      cid;
    uint8             scanTimestamp[XPAN_WIFI_SCAN_TIMESTAMP_LENGTH];
    bool              moreData;
    uint8             numBssids;    /*! This corresponds to the number of ApScanResults */
    ApScanResult*     apScanResult[]; /*! The App must free each ApScanResult pointer in this flexible array */
} GattXpanWiFiScanResultsInd;


typedef struct
{
    GattXpanMessageId id;
    ConnectionId      cid;
    uint16            primaryFrequencyMHz;
    uint8             targetTsf[XPAN_TARGET_TSF_LENGTH];
    uint8             bandwidthMHz;
} GattXpanChannelSwitchAnnouncementInd;


typedef struct
{
    GattXpanMessageId id;
    ConnectionId      cid;
    uint16            udpSyncPort;
} GattXpanUdpSyncPortInd;


typedef struct
{
    GattXpanMessageId id;
    ConnectionId      cid;
} GattXpanRoamingRequestInd;


typedef struct
{
    GattXpanMessageId id;
    ConnectionId      cid;
    uint8             multicastMacAddress[GATT_XPAN_SERVER_MAC_ADDRESS_SIZE];
} GattXpanMulticastMacAddressInd;

typedef struct
{
    GattXpanMessageId id;
    ConnectionId      cid;
    uint8             useCaseIdentifier;
    uint16            periodicity;
} GattXpanUseCaseIdentifierInd;

typedef struct
{
    GattXpanMessageId id;
    ConnectionId      cid;
    uint8             ssidLength;
    uint8*            ssid;  /*! The App must free the memory pointed to here */
    uint8             bssId[GATT_XPAN_SERVER_BSSID_SIZE];
    uint8             ptk[GATT_XPAN_SERVER_WIFI_TEMPORAL_KEY_SIZE];
    uint8             gtk[GATT_XPAN_SERVER_WIFI_TEMPORAL_KEY_SIZE];
    uint8             dhcpServerIpAddress[GATT_XPAN_SERVER_IPV4_ADDRESS_SIZE];
    uint8             dnsServerIpAddress[GATT_XPAN_SERVER_IPV4_ADDRESS_SIZE];
    uint8             subnetMask[GATT_XPAN_SERVER_IPV4_ADDRESS_SIZE];
    uint8             broadcastAddress[GATT_XPAN_SERVER_IPV4_ADDRESS_SIZE];
    uint8             routerAddress[GATT_XPAN_SERVER_IPV4_ADDRESS_SIZE];
    uint8             ipAddressLeaseTime[GATT_XPAN_SERVER_IP_ADDRESS_TIME_SIZE];
    uint8             renewalTimeValue[GATT_XPAN_SERVER_IP_ADDRESS_TIME_SIZE];
    uint8             rebindingTimeValue[GATT_XPAN_SERVER_IP_ADDRESS_TIME_SIZE];
    uint8             numIpAddresses;
    uint8*            ipv4Address; /*! The App must free the memory pointed to here */
    uint8*            macAddress;  /*! The App must free the memory pointed to here */
} GattXpanApConnectAssistInd;

typedef struct
{
    GattXpanMessageId id;
    ConnectionId      cid;
    uint8             status;
} GattXpanWiFiChannelSwitchResponseInd;

typedef struct
{
    GattXpanMessageId   id;
    ConnectionId        cid;
    uint8               reason;
    uint8               role;
} GattXpanBearerSwitchFailedInd;

typedef struct
{
    GattXpanMessageId   id;
    ConnectionId        cid;
    uint8               countryString[GATT_XPAN_SERVER_COUNTRY_STRING_SIZE];
} GattXpanCountryStringInd;

typedef struct
{
    GattXpanMessageId id;
    ConnectionId      cid;
    uint8             state;
    uint8             reason;
} GattXpanSapStateInd;

typedef struct
{
    GattXpanMessageId id;
    ConnectionId      cid;
    SsidData          connectedEnterpriseSsid;  /*! The App must free the memory pointed to here */
    uint8             bssId[GATT_XPAN_SERVER_BSSID_SIZE];
    uint16            primaryFrequency;
    uint8             ipv4Address[4];
    uint8             ipv6Address[16];
    uint8             macAddress[GATT_XPAN_SERVER_MAC_ADDRESS_SIZE];
    Identity          identity;                 /*! The App must free the memory pointed to here */
    Password          password;                 /*! The App must free the memory pointed to here */
    uint8             securityMode;
    uint8             countryString[GATT_XPAN_SERVER_COUNTRY_STRING_SIZE];
} GattXpanConnectedEnterpriseSsidInd;

/*! @brief Definition of data required for the initialisation
*          of the XPAN Server Library.
*/
typedef struct
{
    uint16                      l2capTcpPort;
    uint16                      udpPort;
    uint8                       mDnsSrvUuid[16];
    MacAddress                  macAddress;
    PresentDevices              numDevices;
    VoiceBackChannelPeriodicity periodicity;
    TwtStatus                   twtStatus;
    SapConnectionStatus         sapConnectionStatus;
} GattXpanInitData;

/*! @brief Definition of data for the client configuration.
*/
typedef struct
{
    uint16 storedSsidClientCfg:2;
    uint16 ipv4AddressClientCfg:2;
    uint16 ipv6AddressClientCfg:2;
    uint16 l2capTcpPortClientCfg:2;
    uint16 udpPortClientCfg:2;
    uint16 connectedDevicesClientCfg:2;
    uint16 clearToSendCfg:2;
    uint16 bearerPreferenceClientCfg:2;
    uint16 macAddressesClientCfg:2;
    uint16 requestedSapPowerStateCfg:2;
    uint16 serverFeaturesCfg:2;
    uint16 audioBearerSwitchResponseCfg:2;
    uint16 numDevicesPresentClientCfg:2;
    uint16 voiceBackChannelPeriodicityClientCfg:2;
    uint16 requestWiFiScanResultsClientCfg:2;
    uint16 roamingRequestResponseClientCfg:2;
    uint16 wiFiScanResultsClientCfg:2;
    uint16 preferredChannelsClientCfg:2;
    uint16 wiFiChannelSwitchRequestClientCfg:2;
    uint16 supportedWiFiChannelsClientCfg:2;
    uint16 twtStatusClientCfg:2;
    uint16 sapConnectionStatusClientCfg:2;
} GattXpanServerConfig;

/*! @brief Instantiate the GATT XPAN Server Service Library.

    The GATT Service Init function is responsible for allocating its instance memory
    and returning a unique service handle for that instance. The Service handle is
    then used for the rest of the API.

    @param theAppTask The client task that will receive messages from this Service.
    @param startHandle The first handle in the ATT database for this Service instance.
    @param endHandle The last handle in the ATT database for this Service instance.
    @param initData The initialisation data to set, should be freed in application.

    @return ServiceHandle If the service handle returned is 0, this indicates a failure
                             during GATT Service initialisation.
*/
ServiceHandle GattXpanServerInit(
                     AppTask theAppTask,
                     uint16  startHandle,
                     uint16  endHandle,
                     const GattXpanInitData* initData);

/*!
    \brief Add configuration for a paired peer device, identified by its
    Connection ID (CID).

    \param srvcHndl Instance handle for the service.
    \param cid The Connection ID to the peer device.
    \param config Client characteristic configurations for this connection.
           If this is NULL, this indicates a default config should be used for the
           peer device identified by the CID.
    \return status_t status of the Add Configuration operation.
*/
status_t GattXpanServerAddConfig(
                  ServiceHandle               srvcHndl,
                  ConnectionId                cid,
                  GattXpanServerConfig *const config);

/*!
    \brief Remove the configuration for a peer device, identified by its
           Connection ID.

    This removes the configuration for that peer device from the
    service library, freeing the resources used for that config.
    This should only be done when the peer device is disconnecting.

    \param srvcHndl The GATT service instance handle.
    \param cid A Connection ID for the peer device.

    \return GattXpanServerConfig Pointer to the peer device configuration
            data. It is the application's responsibility to cache/store
            this between connections of paired peer devices, and for
            freeing the allocated memory.
            If the ConnectionId is not found, the function will return NULL.
*/
GattXpanServerConfig* GattXpanServerRemoveConfig(
                        ServiceHandle srvcHndl,
                        ConnectionId  cid);

/*!
    \brief Get the configuration for a peer device, identified by its
           Connection ID.

    \param srvcHndl The GATT service instance handle.
    \param cid A Connection ID for the peer device.

    \return GattXpanServerConfig Pointer to the peer device configuration
            data. It is the application's responsibility to cache/store
            this between connections of paired peer devices, and for
            freeing the allocated memory.
            If the ConnectionId is not found, the function will return NULL.
*/
GattXpanServerConfig* GattXpanServerGetConfig(
                        ServiceHandle srvcHndl,
                        ConnectionId  cid);

/*!
    \brief Sets the Stored Ssids (Service Set ID) characteristic in the instance's data.

    \param srvcHandle The GATT service instance handle.
    \param storedSsid A list of ssids that are stored persistently by the application.

    \return TRUE if successful, FALSE otherwise.
*/
bool GattXpanServerSetStoredSsids(ServiceHandle srvcHandle, const StoredSsid *storedSsid);

/*!
    \brief Sets the L2CAP TCP Port characteristic in the instances data.

    \param srvcHandle The GATT service instance handle.
    \param tcpPort The TCP port on the server, that the client can use to establish a TCP/IP
           connection. The TCP/IP connection can be used to carry L2CAP traffic.
           The TCP port shall be connectable using the IP addresses exposed by the server.

    \return TRUE if successful, FALSE otherwise.
*/
bool GattXpanServerSetL2capTcpPort(ServiceHandle srvcHandle, uint16 tcpPort);

/*!
    \brief Sets the UDP Port characteristic in the instances data.

    \param srvcHandle The GATT service instance handle.
    \param udpPort The Server UDP port number that the client can send audio data, AVDTP
           media and/or synchronous packets to.
           This port is available on any IPv4 or IPv6 address exposed by the server.

    \return TRUE if successful, FALSE otherwise.
*/
bool GattXpanServerSetUdpPort(ServiceHandle srvcHandle, uint16 udpPort);

/*!
    \brief Sets the mDns Srv Uuid characteristic in the instances data.

    \param srvcHandle The GATT service instance handle.
    \param uuid The 128-bit mDNS SRV UUID that can be used to allow a client to
                reconnect to this device using an XPAN bearer.
                The value should be static for the lifetime of the bonding between the two
                devices.
                This value shall be either randomly generated or derived from the server's
                Identity Root. It shall not be in any way derived from any other shared
                secret between the two devices (client and server).
                Note: The XPAN server does not free the data pointed to by the 'uuid' parameter.

    \return TRUE if successful, FALSE otherwise.
*/
bool GattXpanServerSetmDnsSrvUuid(ServiceHandle srvcHandle, uint8 *uuid);

/*!
    \brief Sets the Twt Configuration characteristic in the instances data.

    \param srvcHandle The GATT service instance handle.
    \param cid The Connection Id of the connected client that is being configured.
    \param configuration The Twt Configuration to be set for the connected client.
           Note: The XPAN server does not free the data pointed to by the
           'configuration' parameter.

    \return TRUE if successful, FALSE otherwise.
*/
bool GattXpanServerSetTwtConfiguration(ServiceHandle srvcHandle, ConnectionId cid,
                                        TwtConfiguration *configuration);

/*!
    \brief Sets the Clear to Send characteristic on the server to indicate to the
           client that it (the server) is ready (or not) to accept audio data over XPAN.

    \param srvcHandle The GATT service instance handle.
    \param cid The Connection Id of the connected client that is being configured.
    \param clearToSend The value to set in the 'Clear to Send' characteristic.

    \return TRUE if successful, FALSE otherwise.
*/
bool GattXpanServerSetClearToSend(ServiceHandle srvcHandle, ConnectionId cid,
                                  ClearToSend clearToSend);

/*!
    \brief Adds an SSID to the IPv4 Address characteristic. Note: the added SSID
           has no IPv4 addresses associated with it, these must be added by
           calling GattXpanServerAddIpv4Address().

    \param srvcHandle The GATT service instance handle.
    \param ssid The value of the SSID being added. Note: The XPAN server does not free
                the data pointed to by the 'ssid' parameter.
    \param ssidLen The length of the SSID being added.
    \param bssid The value of the BSSID being added. Note: The BSSID is of length GATT_XPAN_SERVER_BSSID_SIZE.

    \return TRUE if successful, FALSE otherwise.
*/
bool GattXpanServerAddIpv4AddressSsid(ServiceHandle srvcHandle, uint8 *ssid,
                                        uint8 ssidLen, uint8 *bssid);

/*!
    \brief Removes the SSID from the IPv4 Address characteristic.

    \param srvcHandle The GATT service instance handle.
    \param ssid Identifies the SSID value being removed.
    \param ssidLen Length of the SSID value being removed.

    \return TRUE if successful, FALSE otherwise.
*/
bool GattXpanServerRemoveIpv4AddressSsid(ServiceHandle srvcHandle, uint8 *ssid,
                                         uint8 ssidLen);
/*!
    \brief Adds a new IPv4 address to an SSID. The IPv4Address characteristic
           on the XPAN server is updated to reflect this change.
           Subscribed clients are notified when an address is added/updated.

    \param srvcHandle The GATT service instance handle.
    \param Ssid The SSID associated with the IPv4 address being added/updated.
    \param ssidLen Length of the SSID.
    \param ipv4Address The IPv4 Address being added/updated.
    \param audioLocation Associated audio location for the address being added.
                         The Application can specify multiple audio locations by OR'ing
                         multiple audio locations into this parameter.

    \param role The role associated with the IPv4 address being added/updated.
    \param status The current status of this IP address.

    \return TRUE if successful, FALSE otherwise.
*/
bool GattXpanServerAddIpv4Address(ServiceHandle srvcHandle, uint8 *ssid,
                                  uint8 ssidLen, uint8 *ipv4Address,
                                  GattXpanAudioLoc audioLocation, GattXpanRole role,  uint8* macAddress, GattXpanIpAddressStatus status);

/*!
    \brief Adds a new IPv4 address to an SSID. The IPv4Address characteristic
           on the XPAN server is updated to reflect this change.
           Subscribed clients are notified when an address is added/updated if the notify bit is set.

    \param srvcHandle The GATT service instance handle.
    \param Ssid The SSID associated with the IPv4 address being added/updated.
    \param ssidLen Length of the SSID.
    \param ipv4Address The IPv4 Address being added/updated.
    \param audioLocation Associated audio location for the address being added.
                         The Application can specify multiple audio locations by OR'ing
                         multiple audio locations into this parameter.

    \param role The role associated with the IPv4 address being added/updated.
    \param status The current status of this IP address.
    \param notify Notify the clients if TRUE, not if FALSE.

    \return TRUE if successful, FALSE otherwise.
*/
bool GattXpanServerAddIpv4AddressV2(ServiceHandle srvcHandle, uint8 *ssid,
                                    uint8 ssidLen, uint8 *ipv4Address,
                                    GattXpanAudioLoc audioLocation, GattXpanRole role,
                                    uint8* macAddress, GattXpanIpAddressStatus status,
                                    bool notify);

/*!
    \brief Removes an IPv4 address from an SSID. The IPv4Address characteristic
           on the XPAN server is updated to reflect this change.

    \param srvcHandle The GATT service instance handle.
    \param Ssid The SSID associated with the IPv4 address being removed.
    \param ssidLen Length of the ssid.
    \param ipv4Address The IPv4 Address being removed.

    \return TRUE if successful, FALSE otherwise.
*/
bool GattXpanServerRemoveIpv4Address(ServiceHandle srvcHandle, uint8 *ssid,
                                     uint8 ssidLen, uint8 *ipv4Address);

/*!
    \brief Adds an SSID to the IPv6 Address characteristic. Note: the added SSID
           has no IPv6 addresses associated with it, these must be added by
           calling GattXpanServerAddIpv6Address().

    \param srvcHandle The GATT service instance handle.
    \param Ssid The value of the SSID being added. Note: The XPAN server does not free
                the data pointed to by the 'ssid' parameter.
    \param ssidLen Length of the SSID.
    \param bssid The value of the BSSID being added. Note: The BSSID is of length GATT_XPAN_SERVER_BSSID_SIZE.

    \return TRUE if successful, FALSE otherwise.
*/
bool GattXpanServerAddIpv6AddressSsid(ServiceHandle srvcHandle, uint8 *ssid, uint8 ssidLen,
                                      uint8 *bssid);

/*!
    \brief Removes an SSID from the IPv6 Address characteristic.

    \param srvcHandle The GATT service instance handle.
    \param ssid Identifies the SSID value being removed.
    \param ssidLen The length of the SSID value being removed.

    \return TRUE if successful, FALSE otherwise.
*/
bool GattXpanServerRemoveIpv6AddressSsid(ServiceHandle srvcHandle, uint8 *ssid,
                                         uint8 ssidLen);

/*!
    \brief Add an IPv6 address to an SSID, or update information for an existing IPv6 address.
           The IPv6Address characteristic on the XPAN server is updated to reflect this change.

    \param srvcHandle The GATT service instance handle.
    \param Ssid The SSID associated with the IPv6 address being added/updated.
    \param ssidLen length of the SSID associated with the IPv6 address being added/updated.
    \param ipv6Address The IPv6 Address being added/updated.
    \param audioLocation Associated audio location for the address being added.
                         Multiple audio locations can be OR'd if required.
    \param role The role associated with the IPv6 address being added/updated.
    \param status The current status of this IP address.

    \return TRUE if successful, FALSE otherwise.
*/
bool GattXpanServerAddIpv6Address(ServiceHandle srvcHandle, uint8 *ssid,
                                  uint8 ssidLen, uint8 *ipv6Address,
                                  GattXpanAudioLoc audioLocation, GattXpanRole role,
                                  uint8* macAddress,
                                  GattXpanIpAddressStatus status);

/*!
    \brief Add an IPv6 address to an SSID, or update information for an existing IPv6 address.
           The IPv6Address characteristic on the XPAN server is updated to reflect this change.
           Subscribed clients are notified when an address is added/updated if the notify bit is set.

    \param srvcHandle The GATT service instance handle.
    \param Ssid The SSID associated with the IPv6 address being added/updated.
    \param ssidLen length of the SSID associated with the IPv6 address being added/updated.
    \param ipv6Address The IPv6 Address being added/updated.
    \param audioLocation Associated audio location for the address being added.
                         Multiple audio locations can be OR'd if required.
    \param role The role associated with the IPv6 address being added/updated.
    \param status The current status of this IP address.
    \param notify Notify the clients if TRUE, not if FALSE.

    \return TRUE if successful, FALSE otherwise.
*/
bool GattXpanServerAddIpv6AddressV2(ServiceHandle srvcHandle, uint8 *ssid,
                                    uint8 ssidLen, uint8 *ipv6Address,
                                    GattXpanAudioLoc audioLocation, GattXpanRole role,
                                    uint8* macAddress,
                                    GattXpanIpAddressStatus status,
                                    bool notify);

/*!
    \brief Removes an IPv6 address from an SSID. The IPv6Address characteristic
           on the XPAN server is updated to reflect this change.

    \param srvcHandle The GATT service instance handle.
    \param Ssid The SSID associated with the IPv6 address being removed.
    \param ssidLen Length of the ssid.
    \param ipv6Address The IPv6 Address being removed.

    \return TRUE if successful, FALSE otherwise.
*/
bool GattXpanServerRemoveIpv6Address(ServiceHandle srvcHandle, uint8 *ssid,
                                     uint8 ssidLen, uint8 *ipv6Address);
/*!
    \brief Sets the Bearer preference characteristic in the GATT service instance.
           Note: This API stores the value sent by the application and notifies the configured clients.

    \param srvcHandle The GATT service instance handle.
    \param preference the value to be set in the Bearer preference characteristic.

    \return TRUE if successful, FALSE otherwise.
*/
bool GattXpanServerSetBearerPreference(ServiceHandle srvcHandle, BearerPreference preference);

/*!
    \brief Sets the characteristic bit Mask in the GATT service instance,
           for which the application wish to take control of the characteristic.

    \param srvcHandle The GATT service instance handle.
    \param characteristicBitMask an array of size GATT_XPAN_CHARACTERISTICS_MASK_SIZE for Bit mask for the characteristic selection.
    \param characteristicBitMaskSize array size of characteristicBitMask.

    \return TRUE if successful, FALSE otherwise.
*/
bool GattXpanServerEnableCharacteristicControl(ServiceHandle srvcHandle, uint32 *characteristicBitMask, uint8 characteristicBitMaskSize);

/*!
    \brief Notify the Bearer preference characteristic to the target client cid.
           Note: This API does not save the values sent by the application and is only for notifying the client.

    \param srvcHandle The GATT service instance handle.
    \param cid The connection id of the client to be notified.
    \param preference The preferred Bearer value.
    \param notifyAll set to TRUE to ignore the target cid and notify to all connected clients.

    \return TRUE if successful, FALSE otherwise.
*/
bool GattXpanServerNotifyBearerPreference(ServiceHandle srvcHandle, ConnectionId cid, BearerPreference preference, bool notifyAll);

/*!
    \brief Send the Bearer Preference response to the GATT Server library,
           Application shall call this API only if GATT_XPAN_SERVER_BEARER_PREFERENCE_READ_IND received from GATT Server.
           Note: This API does not save the values sent by the application and is only for responding to the read ind.
           

    \param srvcHandle The GATT service instance handle.
    \param cid The connection id of the client to be notified.
    \param preference The preferred Bearer value.

    \return TRUE if successful, FALSE otherwise.
*/
bool GattXpanServerBearerPreferenceReadRsp(ServiceHandle srvcHandle, ConnectionId cid, BearerPreference preference);

/*!
    \brief Sets the Connected devices characteristic in the GATT service instance. This should
           reflect the list of devices that the server is currently connected to.

    \param srvcHandle The GATT service instance handle.
    \param connectedDevices A list of devices that the server is currently connected to.

    \return TRUE if successful, FALSE otherwise.
*/
bool GattXpanServerSetConnectedDevices(ServiceHandle srvcHandle, ConnectedDevices *connectedDevices);

/*!
    \brief Sets the Requested SAP power state characteristic in the GATT service instance.

    \param srvcHandle The GATT service instance handle.
    \param state The state to be set.

    \return TRUE if successful, FALSE otherwise.
*/
bool GattXpanServerSetRequestedSapPowerState(ServiceHandle srvcHandle, RequestedSapPowerState state);

/*!
    \brief Notify the Requested SAP power state characteristic to the target client cid.
           Note: This API does not save the values sent by the application and is only for notifying the client.

    \param srvcHandle The GATT service instance handle.
    \param cid The connection id of the client to be notified.
    \param state The SAP Power state to be set.
    \param notifyAll set to TRUE to ignore the target cid and notify to all connected clients.

    \return TRUE if successful, FALSE otherwise.
*/
bool GattXpanServerNotifyRequestedSapPowerState(ServiceHandle srvcHandle, ConnectionId cid, RequestedSapPowerState state, bool notifyAll);

/*!
    \brief Configures the set of MAC address + Audio Location pairs that are exposed by the
           MAC Address characteristic, i.e. each MacAddress has an associated Audio Location
           and both the MAC Address and the corresponding Audio Location are set by this API.

    \param srvcHandle The GATT service instance handle.
    \param macAddress The full set of 'MAC address + Audio Location' pairs that shall be
                      exposed by the MAC Address characteristic.

    \return TRUE if successful, FALSE otherwise.
*/
bool GattXpanServerSetMacAddress(ServiceHandle srvcHandle, const MacAddress *macAddress);

/*!
    \brief Sets the Server Features characteristic in the GATT service instance.

    \param srvcHandle The GATT service instance handle.
    \param serverFeatures A bitfield of all the features the server supports.

    \return TRUE if successful, FALSE otherwise.
*/
bool GattXpanServerSetServerFeatures(ServiceHandle srvcHandle, const XpanServerFeatures serverFeatures);

/*!
    \brief Sets the server's response to the client's Audio Bearer Switch Request.
           The characteristic will notify as long as the value is valid.

    \param srvcHandle The GATT service instance handle.
    \param response The server's response to the client's Audio Bearer Switch Request.
    \param cid The Connection ID of the client device that is being responded to.

    \return TRUE if successful, FALSE otherwise.
*/
bool GattXpanServerSetAudioBearerSwitch(ServiceHandle srvcHandle, const XpanAudioBearerSwitchResponse response, ConnectionId cid);

/*!
    \brief Sets the Num Devices Present characteristic, which is used to inform the client of the number of
           devices, e.g. earbuds, that are currently present.

    \param srvcHandle The GATT service instance handle.
    \param numDevices The number of devices that are present on the server side.

    \return TRUE if successful, FALSE otherwise.
*/
bool GattXpanServerSetNumDevicesPresent(ServiceHandle srvcHandle, const PresentDevices numDevices);

/*!
    \brief This API informs the client of the periodicity of the voice back channel packets sent from the server to the client, in
           milliseconds. Specifically this API sets the Voice Back Channel Periodicity Characteristic.

    \param srvcHandle The GATT service instance handle.
    \param periodicity Periodicity of voice back channel packets, in milliseconds.

    \return TRUE if successful, FALSE otherwise.
*/
bool GattXpanServerSetVoiceBackChannelPeriodicity(ServiceHandle srvcHandle, const VoiceBackChannelPeriodicity periodicity);

/*!
    \brief Sets the TWT Status characteristic. If a bit is set in the Audio
           Location, then a TWT connection is present in that audio location. Otherwise, no TWT
           connection is present.

    \param srvcHandle The GATT service instance handle.
    \param twtStatus  The TWT Status sent by XPAN Manager

    \return TRUE if successful, FALSE otherwise.
*/
bool GattXpanServerSetTwtStatus(ServiceHandle srvcHandle, const TwtStatus twtStatus);

/*!
    \brief Sets the SAP Connection Status characteristic. If a bit is set in the Audio
           Location, then a SAP connection is present in that audio location. Otherwise, no SAP
           connection is present.

    \param srvcHandle The GATT service instance handle.
    \param sapConnectionStatus  The SAP Connection Status sent by XPAN Manager

    \return TRUE if successful, FALSE otherwise.
*/
bool GattXpanServerSetSapConnectionStatus(ServiceHandle srvcHandle, const SapConnectionStatus sapConnectionStatus);

/*!
    \brief Gets the Stored Ssids characteristic in the instances data.

    \param srvcHandle The GATT service instance handle.

    \return The value stored in the Stored Ssid characteristic for the instance.
*/
StoredSsid* GattXpanGetStoredSsid(ServiceHandle srvcHandle);

/*!
    \brief Gets the IPv4 Address characteristic in the instances data.

    \param srvcHandle The GATT service instance handle.

    \return The value stored in the IPv4 Address characteristic for the instance.
*/
Ipv4Address* GattXpanGetIpv4Addresses(ServiceHandle srvcHandle);

/*!
    \brief Gets the IPv6 Address characteristic in the instances data.

    \param srvcHandle The GATT service instance handle.

    \return The value stored in the IPv6 Address characteristic for the instance.
*/
Ipv6Address* GattXpanGetIpv6Addresses(ServiceHandle srvcHandle);

/*!
    \brief This API requests the client to provide Wi-Fi scan results. The request is sent
           as a notification to all clients that have registered for notifications for
           this characteristic.

    \param srvcHandle The GATT service instance handle.

    \return TRUE if successful, FALSE otherwise.
*/
bool GattXpanServerSetRequestWiFiScanResults(ServiceHandle srvcHandle, ConnectionId cid);

/*!
    \brief This API requests the server to notify the client of whether the Roaming Request was accepted.
           The client associated with the specified cid will be notified providing the client has subscribed
           for the notification.

    \param srvcHandle The GATT service instance handle.
    \param cid        The connection id of the client to be notified.
    \param status     The status of the response.

    \return TRUE if successful, FALSE otherwise.
*/
bool GattXpanServerNotifyRoamingRequestResponse(ServiceHandle srvcHandle, ConnectionId cid, XpanRoamingRequestStatus status);

/*!
    \brief This API used by the server to notify the results of Wi-Fi scanning to the client.
           The client associated with the specified cid will be notified providing the client has subscribed
           for the notification.

    \param srvcHandle     The GATT service instance handle.
    \param cid            The connection id of the client to be notified.
    \param wiFiScanResults   The list of scanned wifi.

    \return TRUE if successful, FALSE otherwise.
*/
bool GattXpanServerNotifyWiFiScanResults(ServiceHandle srvcHandle, ConnectionId cid, WiFiScanResults* wiFiScanResults);
/*!
    \brief This API requests the server to notify the client about list of good WiFi channels.
           The client associated with the specified cid will be notified providing the client has subscribed
           for the notification.

    \param srvcHandle     The GATT service instance handle.
    \param cid            The connection id of the client to be notified.
    \param prefChannels   The preferred channels list.

    \return TRUE if successful, FALSE otherwise.
*/
bool GattXpanServerNotifyPreferredChannels(ServiceHandle srvcHandle, ConnectionId cid, PreferredChannels* prefChannels);

/*!
    \brief This API requests the server to notify the client about changing the wifi channels.
           The client associated with the specified cid will be notified providing the client has subscribed
           for the notification.

    \param srvcHandle     The GATT service instance handle.
    \param cid            The connection id of the client to be notified.
    \param priFreq        Center Frequency of current channel

    \return TRUE if successful, FALSE otherwise.
*/
bool GattXpanServerNotifyWiFiChannelSwitchRequest(ServiceHandle srvcHandle, ConnectionId cid, XpanWiFiChannelSwitchRequestPriFreq priFreq);

/*!
    \brief This API requests the server to notify the client about list of supported WiFi channels.
           The client associated with the specified cid will be notified providing the client has subscribed
           for the notification.

    \param srvcHandle              The GATT service instance handle.
    \param cid                     The connection id of the client to be notified.
    \param supportedWiFiChannels   The supported WiFi channels list.

    \return TRUE if successful, FALSE otherwise.
*/
bool GattXpanServerNotifySupportedWiFiChannels(ServiceHandle srvcHandle, ConnectionId cid, SupportedWiFiChannels* supportedWiFiChannels);

/*!
    \brief Frees the contents of a Control Point Opcode Message. Note: This API frees any
           dynamically allocated memory referenced from within the Control Point Opcode
           Message, but it does not free the Control Point Opcode Message itself.
*/
void GattXpanServerFreeControlPointMessageContents(void *message);

/*!
    \brief Terminates the server by freeing instance memory and deregistering the
           handle from GATT, to make service handle invalid.

    \param srvcHandle The GATT service instance handle.

    \return If the deregistering is successful it will return TRUE, otherwise FALSE.
*/
bool GattXpanServerTerminate(ServiceHandle srvcHandle);

#endif /* EXCLUDE_GATT_XPAN_SERVER_MODULE */

#endif /* GATT_XPAN_SERVER_H */
